<template>
    <view>
        <block v-if="isAdmin">
            <cmpt-comm-list
                type="admin-meet"
                :search="search"
                :_menus="sortMenus"
                :_items="sortItems"
                route="admin/user_list"
                sortMenusDefaultIndex="0"
                topBottom="50"
                placeholder="搜索"
                @list="bindCommListCmpt"
            >
                <view slot="searchEnd">
                    <button @tap="url" :data-url="'../export/admin_user_export?condition=' + dataList.condition" class="btn mid radius bg-admin text-white margin-right-s">
                        <text class="icon-down margin-right-xxs"></text>
                        导出用户资料
                    </button>
                </view>

                <!-- List Begin -->
                <view class="admin-comm-list">
                    <view v-if="dataList && dataList.total" class="load text-grey">共有{{ dataList.total }}条符合条件记录</view>

                    <view class="item" v-for="(item, index) in dataList.list" :key="index">
                        <view class="header">
                            <view class="left text-cut">{{ item.USER_NAME }}</view>
                            <view class="right"></view>
                        </view>

                        <view class="info">
                            <view class="info-item" @tap="url" data-type="phone" :data-url="item.USER_MOBILE">
                                <view class="title">手机</view>
                                <view class="mao">：</view>
                                <view class="content">
                                    {{ item.USER_MOBILE || '未填写' }}
                                    <text v-if="item.USER_MOBILE" class="icon-phone margin-left-s"></text>
                                </view>
                            </view>

                            <view class="info-item">
                                <view class="title">城市</view>
                                <view class="mao">：</view>
                                <view class="content">{{ item.USER_CITY }}</view>
                            </view>

                            <view class="info-item">
                                <view class="title">行业</view>
                                <view class="mao">：</view>
                                <view class="content">{{ item.USER_TRADE }}</view>
                            </view>

                            <view class="info-item">
                                <view class="title">单位</view>
                                <view class="mao">：</view>
                                <view class="content">{{ item.USER_WORK }}</view>
                            </view>

                            <view class="info-item">
                                <view class="title">注册</view>
                                <view class="mao">：</view>
                                <view class="content">{{ item.USER_ADD_TIME }}</view>
                            </view>

                            <view class="oprt">
                                <view @tap="bindDelTap" :data-id="item.USER_MINI_OPENID" class="btn margin-right-s">
                                    <text class="icon-delete margin-right-xxs text-orange"></text>
                                    删除
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
                <!-- List END -->

                <!-- load begin -->

                <!-- parse <template is="listLoadTpl" :data="skin:'text-grey',dataList"/> -->
                <block name="listLoadTpl" v-if="false">
                    <view v-if="!dataList || (dataList && dataList.page < dataList.count)" :class="'load text-grey loading ' + 'text-grey'"></view>
                    <view v-if="dataList && dataList.page > 1 && dataList.page == dataList.count" :class="'load text-grey over ' + 'text-grey'"></view>

                    <block v-if="noHintImg">
                        <image style="height: 500rpx" mode="aspectFit" v-if="dataList && dataList.total == 0" :src="noHintImg" />
                    </block>

                    <block v-else>
                        <view v-if="dataList && dataList.total == 0" :class="'load text-grey ' + 'text-grey'">{{ '暂无记录' ? '暂无记录' : '暂无记录哦~' }}</view>
                    </block>

                    <view style="height: 100rpx"></view>
                </block>
                <!-- load end -->
            </cmpt-comm-list>
        </block>
    </view>
</template>

<script>
const AdminBiz = require('../../../../biz/admin_biz.js');
const pageHelper = require('../../../../helper/page_helper.js');
const cloudHelper = require('../../../../helper/cloud_helper.js');
export default {
    data() {
        return {
            dataList: {
                condition: '',
                total: '',
                list: [],
                page: 0,
                count: 0
            },

            sortItems: '',
            sortMenus: '',
            isAdmin: false,
            search: '',
            noHintImg: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: async function (options) {
        if (!AdminBiz.isAdmin(this)) {
            return;
        }

        //设置搜索菜单
        await this.getSearchMenuFun();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: async function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    methods: {
        url: async function (e) {
            pageHelper.url(e, this);
        },

        bindCommListCmpt: function (e) {
            pageHelper.commListListener(this, e);
        },

        bindDelTap: async function (e) {
            if (!AdminBiz.isAdmin(this)) {
                return;
            }
            let id = pageHelper.dataset(e, 'id');
            let params = {
                id
            };
            let callback = async () => {
                try {
                    let opts = {
                        title: '删除中'
                    };
                    await cloudHelper.callCloudSumbit('admin/user_del', params, opts).then((res) => {
                        pageHelper.delListNode(id, this.dataList.list, 'USER_MINI_OPENID');
                        this.dataList.total--;
                        this.setData({
                            dataList: this.dataList
                        });
                        pageHelper.showSuccToast('删除成功');
                    });
                } catch (e) {
                    console.log('CatchClause', e);
                    console.log('CatchClause', e);
                    console.log(e);
                }
            };
            pageHelper.showConfirm('确认删除？删除不可恢复', callback);
        },

        bindStatusTap: async function (e) {
            if (!AdminBiz.isAdmin(this)) {
                return;
            }
            let id = pageHelper.dataset(e, 'id');
            let status = pageHelper.dataset(e, 'status');
            let params = {
                id,
                status
            };
            try {
                await cloudHelper.callCloudSumbit('admin/user_status', params).then((res) => {
                    pageHelper.modifyListNode(id, this.dataList.list, 'USER_STATUS', status, 'USER_MINI_OPENID');
                    this.setData({
                        dataList: this.dataList
                    });
                    pageHelper.showSuccToast('设置成功');
                });
            } catch (e) {
                console.log('CatchClause', e);
                console.log('CatchClause', e);
                console.log(e);
            }
        },

        getSearchMenuFun: async function () {
            let sortItems = [];
            let sortMenus = [
                {
                    label: '全部',
                    type: '',
                    value: ''
                },
                {
                    label: '正常',
                    type: 'status',
                    value: 1
                },
                {
                    label: '注册时间正序',
                    type: 'sort',
                    value: 'newasc'
                },
                {
                    label: '注册时间倒序',
                    type: 'sort',
                    value: 'newdesc'
                }
            ];
            this.setData({
                sortItems,
                sortMenus
            });
        }
    }
};
</script>
<style>
@import './admin_user_list.css';
@import 'undefined';
</style>
